using System;
using System.Data;
using System.Configuration;
using System.Collections;
using System.Web;
using System.Web.Security;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Web.UI.WebControls.WebParts;
using System.Web.UI.HtmlControls;
using Ent.Web.Helper;
using Ent.Voice.Nomination;
using Ent.Voice.Show;

public partial class ShowEntry : System.Web.UI.Page
{
    protected void Page_Load(object sender, EventArgs e)
    {
        imgEntry.Src = ConfigurationManager.AppSettings["BaseUrl"] + "/Images/dj/entry.gif";
        SetEntry();
    }
    private void SetEntry()
    {
        try
        {
            int id = MathFunction.ConvertToInteger(Request.QueryString["id"]);  //Entry Id
            int pi = MathFunction.ConvertToInteger(Request.QueryString["pi"]);  //PageIndex : View
            int o = MathFunction.ConvertToInteger(Request.QueryString["o"]);    //OrderBy : View
            if (o == 0)
                o = Entry.GetOrderBy(OrderBy.None);
            string c = Request.QueryString["c"];                                //Access code
            //int start = pi * count + 1;
            Entry en = Entry.GetEntry(id, c);
            tblTrans.Visible = false;
            lblMessage.Visible = false;
            cAccess.Visible = false;
            if (en == null)
            {
                lblMessage.Visible = true;
                throw new Exception(ResourceHelper.Get("MSG_InvalidAccess"));
            }
            this.Page.Title = en.Title + " - " + en.EventTitle + " - " + ResourceHelper.Get("SITE_Title");
            lblEntryTitle.Font.Bold = true;
            lblEntryTitle.CssClass = "text14";
            lblEntryTitle.Text = StringHelper.RestrictMaxChar(en.Title, 20);
            lblEventTitle.Font.Bold = true;
            lblEventTitle.CssClass = "text14";
            lblEventTitle.Text = Common.GetImageTextLink("ShowEvent.aspx?id=" + en.EventId.ToString(), "Images/dj/event.gif", StringHelper.RestrictMaxChar(en.EventTitle, 20), 20, new string[] { "c" }) + "<div style=\"float:left\">&nbsp;-&nbsp;</div>";
            lblDescription.Font.Bold = false;
            lblDescription.Text = StringHelper.RestrictMaxChar(en.Description, 150);
            lblNominee.Font.Bold = true;
            lblNominee.Text = Common.GetImageTextLink("ShowUser.aspx?id=" + en.Nominee.UserID, "Images/dj/user.gif", StringHelper.RestrictMaxChar(en.Nominee.FName + " " + en.Nominee.LName, 20), 15);
            bool viewEntry = false;
            if (en != null && en.Accessibility != EventAccess.Private)
            {
                viewEntry = true;
            }
            else
            {
                if (en.AccessCode == c)
                    viewEntry = true;
                else
                {
                    cAccess.Visible = true;
                    cAccess.UserId = en.OrganiserId;
                    if (c != "" && c != null)
                        cAccess.Message = ResourceHelper.Get("MSG_InvalidCode");
                    else
                        cAccess.Message = ResourceHelper.Get("MSG_EnAccessPrivate");
                }
            }
            if (viewEntry)
            {
                tblTrans.Visible = true;
                cView.View = en;
                cView.PageIndex = pi <= 0 ? 1 : pi;
                cView.OrderBy = Entry.GetOrderBy(o);
                lblDescription.Text += "";
            }
        }
        catch (Exception exc)
        {
            lblMessage.Text = "<br />&nbsp;&nbsp;" + Common.GetErrorText(exc.Message);
            imgEntry.Visible = false;
        }
    }
}
